package yunhe.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import yunhe.biz.IProcureBiz;
import yunhe.biz.impl.ProcureBizImpl;
import yunhe.entity.Product;
@WebServlet(name="InsertProductServlet",urlPatterns="/InsertProductServlet")
public class InsertProductServlet extends HttpServlet {
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		response.setContentType("text/html;charset=utf-8");
		Product product=new Product();
		String proBarCode=request.getParameter("proBarCode");
		product.setProBarCode(proBarCode);
		String proNumber=request.getParameter("proNumber");
		product.setProNumber(proNumber);
		String proName=request.getParameter("proName");
		product.setProName(proName);
		String proQual=request.getParameter("proQual");
		product.setProQual(proQual);
		String proUnit=request.getParameter("proUnit");
		product.setProUnit(proUnit);
		String proAddr=request.getParameter("proAddr");
		product.setProAddr(proAddr);
		String proClass=request.getParameter("proClass");
		product.setProClass(proClass);
		String proPurchPri=request.getParameter("proPurchPrice");
		double proPurchPrice=Double.parseDouble(proPurchPri);
		product.setProPurchPrice(proPurchPrice);
		String proSalePri=request.getParameter("proSalePrice");
		double proSalePrice=Double.parseDouble(proSalePri);
		product.setProSalePrice(proSalePrice);
		IProcureBiz ipb=new ProcureBizImpl();
		boolean flag=ipb.insertProduct(product);
		PrintWriter out=response.getWriter();
		if(flag){
			out.print("<script>alert('添加商品信息成功');location.href='/purchase/addProduct.jsp'</script>");
		}else{
			out.print("<script>alert('添加商品信息失败');location.href='/purchase/addProduct.jsp'</script>");
		}
	}
	
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		
		doGet(req, resp);
	}
}
